package  com.cnn.base.controller;

import javax.annotation.Resource;

import com.cnn.base.model.User;
import com.cnn.base.service.UserService;
import com.cnn.base.util.JsonUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
public class UserController {

	@Resource
	private UserService userService;

	@RequestMapping("/getUser")
	public String getUser() {
		return JsonUtil.success(userService.getUser());
	}

	@RequestMapping("/getUserById")
	public String getUserById(String id) {
		return JsonUtil.success(userService.getUserById(Long.valueOf(id)));
	}

	@RequestMapping("/addUser")
	public String addUser(User user) {
		userService.addUser(user);
		return JsonUtil.success();
	}

	@RequestMapping("/updateUser")
	public String updateUser(User user) {
		userService.updateUser(user);
		return JsonUtil.success();
	}

	@RequestMapping("/deleteUser")
	public String deleteUser(String id) {
		userService.deleteUser(Long.valueOf(id));
		return JsonUtil.success();
	}
}
